package com.fengkai.filepost.pdfoutstream.test.solutions;

import lombok.Data;
import lombok.ToString;

/**
 * @author Fengkai
 * @creat 2023/4/4
 */
@Data
public class PractiesStruckNode {

    @Data
    @ToString
    class Node {
        private int value;
        private Node next;

        public int getValue () {
            return value;
        }

        public void setValue (int value) {
            this.value = value;
        }

        public Node getNext () {
            return next;
        }

        public void setNext (Node next) {
            this.next = next;
        }

        public Node (int value) {
            this.value = value;
        }
    }

    public static void main (String[] args) {
        PractiesStruckNode practiesStruckNode = new PractiesStruckNode();
        Node struckNode = practiesStruckNode.getStruckNode(3);
        System.out.println(struckNode);
        System.out.println(getFlipper(struckNode));


    }

    public Node getStruckNode (int size) {
        Node head = new Node((int) ((Math.random() * 500) + 1));
        Node cache = head;
        for (int i = 0; i < size; i++) {
            cache.next = new Node((int) (Math.random() * 500) + 1);
            cache = cache.next;
        }
        return head;
    }

    //翻转单链表
    public static Node getFlipper (Node toChange) {
        Node pre = null;
        Node next = null;
        while (toChange != null){
            next = toChange.next;
            toChange.next = pre;
            pre = toChange;
            toChange = next;
        }
        return pre;
    }
}
